package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from sky_take_out.dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

/*
    @Insert("insert into sky_take_out.dish (name, category_id, price, image, description, status, create_time," +
            " update_time, create_user, update_user) VALUES (#{name},#{categoryId},#{price},#{image},#{description},#{status}" +
            ",#{createTime},#{updateTime},#{createUser},#{updateUser}); ")*/

    /**
     * 添加菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void addDish(Dish dish);


    /**
     * 自己写的分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<Dish> queryPageList(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 标答给的分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    //@Select("select * from sky_take_out.dish where id in (#{ids});")

    /**
     * 判断相应的id的并且禁售的
     * @param ids
     * @return
     */
    List<Dish> selectByidsIfOnSale(List<Long> ids);




    /**
     * 删除dish表中对应的id的菜品
     * @param ids
     */
    void deleteByids(List<Long> ids);

    DishVO selectById(Long id);

    @Select("select * from sky_take_out.dish where category_id =#{categoryId};")
    Dish[] SelectDishListBycategoryId(Long categoryId);

    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    @AutoFill(OperationType.UPDATE)
    void setStatus(Dish dish);

    List<Dish> list(Dish dish);

    Integer countByMap(Map map);

}
